package org.adg.code.controller;

import java.io.IOException;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.adg.code.service.LoginManager;
import org.adg.code.service.LoginManagerImpl;


public class Login {
	/*This method is used to check the username and password for logging in*/
	public void userlogin(HttpServletRequest request, HttpServletResponse response)
	{
		HttpSession session = request.getSession();
		String username = request.getParameter("textfield");
		String password = request.getParameter("textfield2");
		boolean valid=false;
		LoginManager um=new LoginManagerImpl();
		valid=um.valid(username,password);
		try
		{
			if(valid)
			{
				session.setAttribute("uname", username);
				response.sendRedirect("adg.do?method=mainpage");
			}
			else
				response.sendRedirect("index.jsp");
		}
		catch(IOException se)
		{
			System.out.println("Name Error : " + se);
		} 
		
	}
}
